package com.cn.lp.openapi.base;

import com.cn.lp.common.utils.BlankAide;
import com.cn.lp.openapi.param.RequestParam;
import feign.Param;
import feign.Util;
import java.nio.charset.Charset;

/**
 * param 处理器
 */
public class ParameterExpander implements Param.Expander {

    private boolean encode = true;

    private Charset charset = Util.UTF_8;

    public static ParameterExpander build(boolean encode, Charset charset) {
        ParameterExpander expander = new ParameterExpander();
        expander.encode = encode;
        expander.charset = charset;
        return expander;
    }

    @Override
    public String expand(Object value) {
        if(BlankAide.isBlank(value)) {
            return null;
        }
        if(value instanceof RequestParam) {
            RequestParam requestParam = (RequestParam) value;
            requestParam.initMap(encode, charset);
            return "requestParam.initMap()";
        }
        return value.toString();
    }

}
